
import {getUser,getToken} from '@/utils'
const user = {
  state: {
    userName: '',
    status: '',
    token: '',
    openId:'',
    avatar: '',
    nickname:'',
    roles: [],
  },

  mutations: {
    SET_CODE: (state, code) => {
      state.code = code
    },
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_NICKNAME:(state, nickname)=>{
      state.nickname = nickname
    },
    SET_STATUS: (state, status) => {
      state.status = status
    },

    SET_AVATAR: (state, avatar) => {
      state.avatar = avatar
    },
    SET_ROLES: (state, roles) => {
      state.roles = roles
    },
    SET_OPENID: (state, openId) => {
      state.openId = openId
    }
  },

  actions: {
    // 用户名登录
    LoginByUsername({ commit }, userInfo) {
      return new Promise((resolve, reject) => {

      })


    },

    // 获取用户信息
    GetUserInfo({ commit, state },userName) {
      return new Promise((resolve, reject) => {
          resolve()

      })
    },


    // 登出
    LogOut({ commit, state }) {
      return new Promise((resolve, reject) => {

        resolve()
      })
    },

    // 前端 登出
    FedLogOut({ commit }) {
      return new Promise(resolve => {
        resolve()
      })
    },

    // 动态修改权限
    ChangeRoles({ commit }, role) {
      return new Promise(resolve => {
          resolve()

      })
    },
    setUserInfo({ commit }) {
      return new Promise(resolve => {
        var user =getUser();
        var token=getToken();
        commit('SET_NICKNAME',user.nickname);
        commit('SET_OPENID',user.openid);
        commit('SET_TOKEN',token);
        commit('SET_AVATAR',user.headimgurl);
        resolve();
      })
    },
    removeUserInfo({commit}){
      return new Promise(resolve => {
        localStorage.removeItem("user");
        localStorage.removeItem("token");
        commit('SET_NICKNAME','');
        commit('SET_OPENID','');
        commit('SET_TOKEN','');
        commit('SET_AVATAR','');
        resolve();
      })
    }
  }
}

export default user
